package com.legendshop.openportal.sdk.model.request.v4;

import cn.hutool.core.util.StrUtil;
import com.legendshop.openportal.sdk.annotation.DateValid;
import com.legendshop.openportal.sdk.model.PageRequest;
import com.legendshop.openportal.sdk.model.constants.DateQueryTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;

import static com.legendshop.openportal.sdk.model.constants.ApiPathConstantsV4.QUERY_PROD_LIST_PAGE_V4;

/**
 * @Description: 商品池分页查询
 * @Author lwj
 * @data 2024/6/28
 **/
@Data
@Accessors(chain = true)
@ApiModel(value = "商品分页查询对象")
public class ProdListPageV4Request extends PageRequest {

    private static final long serialVersionUID = 3445103397509254204L;

    /**
     * 店铺id
     */
    @NotNull(message = "店铺id不能为空")
    @ApiModelProperty("店铺id")
    private Long shopId;

    /**
     * 类目id
     */
    @ApiModelProperty(value = "类目id")
    private Long categoryId;

    /**
     * 商品名称
     */
    @ApiModelProperty(value = "商品名称")
    private String prodName;

    /**
     * 商品id
     */
    @ApiModelProperty(value = "商品id")
    private Long prodId;

    @DateValid(message = "开始时间格式不正确", ignoreEmpty = true)
    @ApiModelProperty(value = "开始时间，需与结束时间同时传")
    private String startDate;

    @DateValid(message = "结束时间格式不正确", ignoreEmpty = true)
    @ApiModelProperty(value = "结束时间，需与开始时间同时传")
    private String endDate;

    @ApiModelProperty(value = "时间查询类型，默认为更新时间")
    private DateQueryTypeEnum dateQueryType;

    @Override
    @ApiModelProperty(hidden = true)
    public String getApiPath() {
        return QUERY_PROD_LIST_PAGE_V4;
    }

    @AssertTrue(message = "开始时间必须小于等于结束时间")
    public boolean getStartDateBeforeEndDate() {
        if (StrUtil.isBlank(startDate)) {
            return StrUtil.isBlank(endDate);
        }
        if (StrUtil.isBlank(endDate)) {
            return false;
        }
        return startDate.compareTo(endDate) <= 0;
    }
}
